package com.aurora.star.controller;

import com.alibaba.fastjson.JSON;
import com.aurora.model.vo.ResultVO;
import com.aurora.neo4j.entity.RelationVo;
import com.aurora.neo4j.service.PersonService;
import com.aurora.service.RedisService;
import com.aurora.service.TopicService;
import com.aurora.spider.utils.SpiderUtil;
import com.aurora.star.dto.StarQueryDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @program: blog-aurora
 * @description: 对外api 无权限校验
 * @author: jonk
 * @create: 2023-08-04 15:48
 **/

@RestController
@Slf4j
@RequestMapping("/star")
public class StarController {

    @Autowired
    TopicService topicService;

    @Resource
    SpiderUtil spiderUtil;
    @Autowired
    RedisService redisService;

    @Resource
    PersonService personService;

    @RequestMapping("/findStarByName")
    public ResultVO<RelationVo> findStarByName(@RequestBody StarQueryDto dto) {
        RelationVo vo =personService.findStarByName(dto);
        log.info("JSON.toJSONString(vo) {}", JSON.toJSONString(vo)) ;
        return ResultVO.ok(vo);

    }
    @RequestMapping("/houyuantuan")
    public String houyuantuanSpider() {

        redisService.set("createPersonRelationByName", 0);
        redisService.set("createPersonRelation", 0);
        redisService.set("houyuantuanEvent", 0);
        //初始化数据
        spiderUtil.houyuantuan();
        return " sucess ";
    }

}